﻿using System.Web.Mvc;
using Pay.Distribution;
using Pay.DTO;
using Pay.IService;
using Pay.TO;

namespace Pay.Web.Areas.Admin.Controllers {

    [RoutePrefix("bill")]
    public class BillController : GeneralController {
        private IBillService _iBillService;
        private IChargeService _iChargeService;

        public BillController(IBillService iBillService, IChargeService iChargeService) {
            _iBillService = iBillService;
            _iChargeService = iChargeService;
        }
        public ActionResult Index() {
            return View();
        }
        /// <summary>
        /// 账单列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public JsonResult GetBills(BillQueryEx query) {
            var model = _iBillService.GetBills(query);
            return Json(ResultToJson.Json(model), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 账单明细
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public JsonResult Get(BillQuery query) {
            var model = _iBillService.GetByMerchant(query);
            return Json(ResultToJson.Json(model), JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        ///  OEM代付充值
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult Recharge(recharge_model model) {
            var result = _iChargeService.RechargeOutpay(model);
            return Json(ResultToJson.Json(result >= 0 ? " 代付充值成功" : "代付充值失败", result), JsonRequestBehavior.AllowGet);
        }
    }
}